package com.example.dongshihao.zyfypt_dsh211.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.example.dongshihao.zyfypt_dsh211.R;

public class LoginActivity extends AppCompatActivity {
    private EditText _et_password,_et_username;
    private Button _btn_user_clear,_btn_psd_look,_btn_psd_clear,_btn_login,_btn_forgot,_btn_user_add;
    private boolean isOpen = false;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        init();
        String msg="欢迎您的到来！！！";
        Toast.makeText(this, "这是一个测试toast", Toast.LENGTH_SHORT).show();
        Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();

        _btn_user_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(LoginActivity.this,RegisterActivity.class);
                startActivity(intent);
            }
        });
        _btn_forgot.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(LoginActivity.this,MainActivity.class);
                startActivity(intent);
            }
        });
    }
    private void init() {
        _btn_forgot = (Button) findViewById(R.id.btn_forgot);
        _btn_login = (Button) findViewById(R.id.btn_login);
        _btn_user_clear = (Button) findViewById(R.id.btn_user_clear);
        _btn_psd_clear = (Button) findViewById(R.id.btn_psd_clear);
        _btn_psd_look = (Button) findViewById(R.id.btn_psd_look);
        _btn_user_add = (Button) findViewById(R.id.btn_user_add);

        _et_password = (EditText) findViewById(R.id.et_password);
        _et_username = (EditText) findViewById(R.id.et_username);


        // 监听文本框内容变化
        _et_username.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                // 获得文本框中的用户
                String user = _et_username.getText().toString();
                // 用户名为空,设置按钮不可见
                if (" ".equals(user)) {
                    _btn_user_clear.setVisibility(View.VISIBLE);
                } else {
                    // 用户名不为空，设置按钮可见
                    _btn_user_clear.setVisibility(View.INVISIBLE);
                }
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {

            }


        });
    }
}
